package cn.example.common.protocol.modules;

import org.artifact.core.lang.IServer;
import org.artifact.core.context.session.ISession;
import org.artifact.core.context.packet.IPacket;
import cn.hutool.core.map.MapProxy;
import java.util.function.Consumer;
import java.util.Collection;
import java.util.Map;
import java.util.List;
import org.artifact.core.constant.ArtifactErrorCode;
import org.artifact.core.exception.ArtifactExceptionUtil;
import org.artifact.core.lang.IModule;
import cn.example.common.protocol.structs.*;

@SuppressWarnings("unchecked")
public interface FriendModule extends IModule{
	
	default int getModuleId(){
		return 2718;
	}
	
	/** 分发  */
	default Consumer<IPacket> disp(ISession session,IPacket packet) {
		switch (packet.getMethodId()) {
			case 25317:{
				return operationFriend(session,packet);
			}
			case 6718:{
				return remarkFriend(session,packet);
			}
			default:
				throw ArtifactExceptionUtil.error(ArtifactErrorCode.NOT_FOND_ACTION);
		}
	}	


	/** 操作好友 */
	default Consumer<IPacket> operationFriend(ISession session,IPacket packet) {
		MapProxy proxy = MapProxy.create(packet.getBody());
		int action = proxy.getInt(-1422950858);
		List<java.lang.Long> friendIds = (List<java.lang.Long>)proxy.get(-1165056198);
		return operationFriend(session, action, friendIds);
	}
	
	/** 操作好友 */
	Consumer<IPacket> operationFriend(ISession session, int action, List<java.lang.Long> friendIds);
	
	default Consumer<IPacket> _operationFriend(ISession session){
		return (IPacket packet) -> {
                if (packet == null){
                    packet = IServer.me().getContext().getPacketFactory().create();
                    packet.setCmd(2718 << 16 ^ 25317);
                } else {
                    packet.getBody().clear();
                }

				session.sendPacket(packet);
			};
	}
	/** 备注好友 */
	default Consumer<IPacket> remarkFriend(ISession session,IPacket packet) {
		MapProxy proxy = MapProxy.create(packet.getBody());
		long friendId = proxy.getLong(-1423055783);
		java.lang.String remark = proxy.getStr(-934624384);
		return remarkFriend(session, friendId, remark);
	}
	
	/** 备注好友 */
	Consumer<IPacket> remarkFriend(ISession session, long friendId, java.lang.String remark);
	
	default Consumer<IPacket> _remarkFriend(ISession session){
		return (IPacket packet) -> {
                if (packet == null){
                    packet = IServer.me().getContext().getPacketFactory().create();
                    packet.setCmd(2718 << 16 ^ 6718);
                } else {
                    packet.getBody().clear();
                }

				session.sendPacket(packet);
			};
	}
	
	
	/** 推送好友 */
	default void notifyFriend(ISession session, List<java.lang.Integer> ids, List<TargetPlayerDTO> list){
		IPacket packet = IServer.me().getContext().getPacketFactory().create();
		packet.setCmd(2718 << 16 ^ 13127);
		packet.getBody().put(104120,ids);
		packet.getBody().put(3322014,list);
		session.sendPacket(packet);
	}
	
	default void notifyFriend(Collection<ISession> sessions, List<java.lang.Integer> ids, List<TargetPlayerDTO> list){
		IPacket packet = IServer.me().getContext().getPacketFactory().create();
		packet.setCmd(2718 << 16 ^ 13127);
		packet.getBody().put(104120,ids);
		packet.getBody().put(3322014,list);
		for (ISession session : sessions) {
			session.sendPacket(packet);
		}
	}
	
}